﻿using ProjectCloth.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProjectCloth.FrmUI.Companys
{
    public partial class CompanyFrm : Form
    {
        private ClothContext db = new ClothContext();
        public string CompanyName = "";
        public int CompanyId = 0;
        public CompanyFrm()
        {
            InitializeComponent();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = (from c in db.Companies.Where(o => o.Enabled == true)
                                        select new
                                        {
                                            CompanyName = c.Name,
                                            c.Remark,
                                            c.Id
                                        }).ToList();
        }

        private void searchBtn_TextChanged(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = (from c in db.Companies.Where(o => o.Enabled == true && o.Name.Contains(searchBtn.Text))
                                        select new
                                        {
                                            CompanyName = c.Name,
                                            c.Remark,
                                            c.Id
                                        }).ToList();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            CompanyName = this.dataGridView1.CurrentRow.Cells["Name"].Value != null ? dataGridView1.CurrentRow.Cells["Name"].Value.ToString() : "";
            CompanyId = this.dataGridView1.CurrentRow.Cells["Id"].Value != null ? (int)dataGridView1.CurrentRow.Cells["Id"].Value : 0;
            this.Close();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //if (dataGridView1.Rows.Count == 1)
            //{
            //    MessageBox.Show("1");
            //}
            //if(dataGridView1.CurrentRow.Index==0&& dataGridView1.Rows.Count >= 1)
            //{
            //    MessageBox.Show("2");
            //}
        }
    }
}
